package com.example.demo.mapper;

import com.example.demo.dto.SearchInfo;
import com.example.demo.entity.Rukujilu;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository()
public interface Rukujilu_Mapper extends BaseMapper<Rukujilu>{

	@Select("SELECT Rukujilu.*, cangku.chanpinname AS chanpinname, Danweixinxi.danweiname AS danweiname, Zhigong.name AS zhigongname, Yunshugongju.chepaihao AS chepaihao"
			+ " FROM Rukujilu"
			+ " JOIN cangku ON Rukujilu.chanpinid = cangku.id"
			+ " JOIN Danweixinxi ON Rukujilu.danweiid = Danweixinxi.id"
			+ " JOIN Zhigong ON Rukujilu.zhigongid = Zhigong.id"
			+ " JOIN Yunshugongju ON Rukujilu.yunshugongjuid = Yunshugongju.id"
			+ " ${where} ${limitstr}")
	public List<Rukujilu> select(SearchInfo info);


	@Select("SELECT COUNT(1) FROM Rukujilu " +
			"JOIN cangku ON Rukujilu.chanpinid = cangku.id " +
			" JOIN Danweixinxi ON Rukujilu.danweiid = Danweixinxi.id " +
			" JOIN Zhigong ON Rukujilu.zhigongid = Zhigong.id " +
			" JOIN Yunshugongju ON Rukujilu.yunshugongjuid = Yunshugongju.id ${where}")
	public long selectCount(SearchInfo info);
	
	@Insert("INSERT INTO Rukujilu (chanpinid, danweiid, zhigongid, yunshugongjuid,caozuoshuliang,rukutime) VALUES (#{chanpinid}, #{danweiid}, #{zhigongid}, #{yunshugongjuid}, #{caozuoshuliang}, #{rukutime})")
	public void insert(Rukujilu Rukujilu);
	
	@Update("UPDATE Rukujilu SET chanpinid = #{chanpinid}, danweiid = #{danweiid}, "
	        + "zhigongid = #{zhigongid}, yunshugongjuid = #{yunshugongjuid} , caozuoshuliang = #{caozuoshuliang} , rukutime = #{rukutime} WHERE id = #{id}")
	public void update(Rukujilu Rukujilu);
	
	
	@Delete("DELETE FROM Rukujilu WHERE id = #{id}")
	public void delete(int id);
	
	@Select("SELECT * FROM Rukujilu WHERE id = #{id}")
	public Rukujilu selectById(int id);
	
}
